package org.totoro.patterns.behavior.interpreter.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YHL
 * @version V1.0
 * @Description: 表达式
 * @date 2018-11-20
 */
public abstract class Expressions {

    public static <V> OperatorPredicate eq(V v, IExpression expression) {
        return new OperatorPredicate(expression, Operator.EQ, v);
    }

    public static <V> ValueExpression valueExpression(V V) {
        return new ValueExpression(V);
    }

    public static <V> CompoundPredicate and(IExpression expression) {

        List<IExpression<Boolean>> expressions = new ArrayList<>();
        expressions.add(expression);
        return new CompoundPredicate(CompoundPredicate.Logic.AND, expressions);
    }

    public static <V> CompoundPredicate and() {
        return new CompoundPredicate(CompoundPredicate.Logic.AND, new ArrayList<>());
    }

    public static <V> CompoundPredicate add(IExpression expression) {

        List<IExpression<Boolean>> expressions = new ArrayList<>();
        expressions.add(expression);
        return new CompoundPredicate(CompoundPredicate.Logic.AND, expressions);
    }


}
